<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <PageTool :show-before="true">
          <template v-slot:before>
            <el-button type="primary" size="small" @click="addManger">添加经纪</el-button>
          </template>
          <template v-slot:after>
            <el-input class="search" placeholder="请输入关键字">
              <el-button slot="append" icon="el-icon-search" />
            </el-input>
          </template>
        </PageTool>
        <template>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="image" label="图片" width="180px">
              <template v-slot="{row}">
                <img class="img" :src="row.image" alt="">>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="名称" width="180px" />
            <el-table-column prop="email" label="邮箱" width="180px" />
            <el-table-column prop="phone" label="电话" width="180px" />
            <el-table-column prop="address" label="地址" width="180px" />
            <el-table-column prop="desc" label="介绍" width="180px" />
            <el-table-column prop="address" label="操作">
              <template v-slot="{row}">
                <el-button type="primary" size="small" @click="edit(row.id)">编辑</el-button>
                <el-button type="danger" size="small" @click="delMang(row.id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页器 -->
          <el-row type="flex" justify="center">
            <el-pagination
              class="page"
              layout="prev, pager, next"
              :total="5"
              @current-change="currentChange"
            />
          </el-row>
        </template>
      </el-card>
      <Dialog
        ref="from"
        :show-dialog.sync="showDialog"
        @updata="updata"
      />
    </div>
  </div>
</template>
<script>
import { getMangerList, delMande } from '@/api/model/manger'
import Dialog from './dialog/dialog.vue'

export default {
  components: { Dialog },
  data() {
    return {
      tableData: [],

      params: {
        _limit: 10,
        _start: 0
      },
      showDialog: false

    }
  },
  async created() {
    this.getMangerList()
  },
  methods: {
    // 分页
    currentChange(page) {
      this.getMangerList()
    },
    // 编辑
    edit(id) {
      this.showDialog = true
      this.$refs.from.EditId(id)
    },
    // 更新列表
    updata() {
      this.getMangerList()
    },
    // 新增经纪
    addManger() {
      this.showDialog = true
      this.getMangerList()
    },
    // 删除经纪
    async delMang(id) {
      this.$confirm('确定删除该员工吗？', '提示', {
        type: 'warning'
      }).then(async() => {
        const res = await delMande(id)
        console.log(res)
        this.getMangerList()
      })
      // console.log(res)
    },
    async getMangerList() {
      const res = await getMangerList(this.params)
      console.log(res)

      this.tableData = res.data
      // console.log(53, this.tableData)
    }
  }
}

</script>
<style lang="scss" scoped>
::v-deep .el-table td {
  padding: 100px 0;
}
.img {
  height: 200px;
  width: 200px;
}
</style>
